<template>
  <div class="home">
    <!-- 面包屑 -->
    <mbx name1="订单管理" name2="订单列表" />
    <!-- card -->
    <el-card class="mt16">
      <el-input
        v-model="k"
        placeholder="请输入您想搜索的内容"
        style="width: 350px"
        @input="search"
        clearable
        @clear="search"
      >
        <template #append>
          <el-button :icon="Search" @click="getlist" />
        </template>
      </el-input>
      <!-- 表格区 -->
      <el-table :data="orderlist" border style="width: 100%" class="mt16">
        <el-table-column fixed type="index" label="#"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column label="是否付款">
          <template #default="scope">
            <el-button
              type="danger"
              v-show="scope.row.pay_status == 0"
              size="mini"
              >未付款</el-button
            >
            <el-button
              type="success"
              v-show="scope.row.pay_status == 1"
              size="mini"
              >已付款</el-button
            >
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column label="下单时间">
          <template #default="scope">
            {{ scope.row.create_time | gtimer }}
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作">
          <template #default="scope">
            <el-button
              type="primary"
              size="small"
              :icon="Edit"
              @click="dialogFormVisible1 = true"
            ></el-button>
            <el-button
              type="success"
              size="small"
              :icon="Location"
              @click="dialogVisible = true"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <el-pagination
        v-model:currentPage="shuju.pagenum"
        v-model:page-size="shuju.pagesize"
        :page-sizes="[5, 10, 15, 20]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
      <!-- 表格区 -->
      <!-- 物流进度 -->
      <el-dialog title="物流进度" v-model="dialogVisible" width="40%">
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in wul"
            :key="index"
            :icon="MoreFilled"
            :color="activity.color"
            :timestamp="activity.time"
          >
            {{ activity.context }}
          </el-timeline-item>
        </el-timeline>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 物流进度 -->
      <!-- 编辑的模态框 -->
      <el-dialog title="修改地址" v-model="dialogFormVisible1">
        <el-form :model="form1" ref="editadd" class="demo-ruleForm">
          <el-form-item label="省市区县">
            <el-cascader
              style="width: 280px"
              v-model="form1.arr"
              :options="city"
              :props="{
                expandTrigger: 'hover',
                value: 'value',
                label: 'label',
                children: 'children',
              }"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址">
            <el-input v-model="form1.name" style="width: 350px"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible1 = false">取 消</el-button>
          <el-button type="primary" @click="xg">确 定</el-button>
        </div>
      </el-dialog>
    </el-card>
    <!-- card -->
  </div>
</template>

<script>
import { toRefs, reactive, onMounted, ref } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { getorder, getorderwl } from "../http/api.js";
import city from "../city/city.js";
import wll from "../wulist/wu.js";
import { Search, Edit, Location, MoreFilled } from "@element-plus/icons-vue";
import _ from "lodash";
export default {
  setup(props) {
    const obj = reactive({
      wul: wll.data,
      city,
      orderlist: [],
      shuju: {
        query: "",
        pagenum: 1,
        pagesize: 6,
      },
      k: "",
      total: 0,
      dialogVisible: false,
      activities: [],
      form1: {
        arr: [],
        name: "",
      },
      dialogFormVisible1: false,
    });
    // 挂载
    onMounted(() => {
      getlist();
    });
    // 渲染数据
    const getlist = async () => {
      const res = await getorder(obj.shuju);
      console.log("订单数据", res);
      obj.orderlist = res.goods;
      obj.total = res.total;
    };

    // 改变每页条数
    const handleSizeChange = (val) => {
      console.log(`${val} items per page`);
      obj.shuju.pagesize = val;
      getlist();
    };
    // 改变页码数
    const handleCurrentChange = (val) => {
      console.log(`current page: ${val}`);
      obj.shuju.pagenum = val;
      getlist();
    };
    // 物流
    const wl = async () => {
      console.log("物流id", id);
      obj.dialogVisible = true;
    };
    // 修改
    const xg = () => {
      obj.dialogFormVisible1 = false;
      ElMessage.success("修改成功哦");
      obj.form1 = {
        arr: [],
        name: "",
      };
    };
    // 搜索
    const search = _.debounce(function () {
      getlist();
    }, 300);
    return {
      ...toRefs(obj),
      handleSizeChange,
      handleCurrentChange,
      xg,
      wl,
      Search,
      search,
      Edit,
      Location,
      MoreFilled,
    };
  },
};
</script>
<style lang="scss" scoped>
.home {
  width: 100%;
}
::v-deep .el-input__inner {
  width: 300px;
}
</style>
